package com.google.gson;

import com.google.gson.b.a;
import com.google.gson.b.c;
import com.google.gson.internal.k;
import java.io.EOFException;
import java.io.Reader;
import java.io.StringReader;

public final class o {
    public j a(a aVar) throws k, q {
        j a;
        boolean o = aVar.o();
        aVar.a(true);
        try {
            a = k.a(aVar);
            aVar.a(o);
        } catch (Throwable e) {
            throw new n("Failed parsing JSON source: " + aVar + " to Json", e);
        } catch (Throwable e2) {
            throw new n("Failed parsing JSON source: " + aVar + " to Json", e2);
        } catch (n e3) {
            if (e3.getCause() instanceof EOFException) {
                a = l.a;
                aVar.a(o);
            } else {
                throw e3;
            }
        } catch (Throwable th) {
            aVar.a(o);
        }
        return a;
    }

    public j a(Reader reader) throws k, q {
        try {
            a aVar = new a(reader);
            j a = a(aVar);
            if (a.j() || aVar.f() == c.END_DOCUMENT) {
                return a;
            }
            throw new q("Did not consume the entire document.");
        } catch (Throwable e) {
            throw new q(e);
        } catch (Throwable e2) {
            throw new k(e2);
        } catch (Throwable e22) {
            throw new q(e22);
        }
    }

    public j a(String str) throws q {
        return a(new StringReader(str));
    }
}
